package com.shxzz.easy12306.services.user.toolkit;

import com.shxzz.easy12306.services.user.common.constant.UserRegisterConstant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

/**
 * 用户复用工具类
 * @author shxzz
 * @create 2024-02-27-23:06
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserReuseUtil {
    /**
     * 获取用户名复用集合分片索引值
     * @return 用户名复用集合分片索引值，范围 {@link UserRegisterConstant#USERNAME_REUSE_SHARDING_COUNT}
     */
    public static int getUsernameReuseShardingIdx(String username) {
        if(!StringUtils.hasLength(username)) return 0;
        return username.hashCode() % UserRegisterConstant.USERNAME_REUSE_SHARDING_COUNT;
    }
}
